% 
clc;
clearvars;
rng('shuffle')
TempDataFile='..\CodesV15NewRunForDoubleCheck\Data\TestAnalizeTempFile.mat';
ParamsFile='..\CodesV15NewRunForDoubleCheck\Data\TestDataset_Params.mat';
Params=load(ParamsFile);
load(TempDataFile)
%% Find Exream Efects
Extreams=false(Test.SNum,1);
NR=1;
ErrorTrshold=0.2;
WTrshold=0.05;
Errors=abs(Test.Label(:,NR)-Test.BestFittedW(:,1,NR));
Extreams(Errors>ErrorTrshold & (Test.BestFittedW(:,1,NR)<WTrshold | Test.BestFittedW(:,1,NR)>(1-WTrshold)))=true;
fprintf('Number of Extream Effect Agents = %d\n',nnz(Extreams))
FittedBeta1=Test.Features(:,39,NR);
AgentBeta1=Params.Params(:,4,NR);
AgentBeta2=Params.Params(:,5,NR);
%%
BasePlotFileName='Plots\ExtreamAnalize1_Fig';
SavePlots=0;
TextSize=14;
%%
YMax=60;
NBin=1:0.5:10;
figure(1);subplot(1,2,1);
histogram(AgentBeta1(Extreams),NBin);
set(gca,'FontSize',TextSize)
xlabel('\beta_1')
ylabel('Number of agents')
% ylim([0,YMax]);
subplot(1,2,2);
histogram(AgentBeta2(Extreams),NBin);
set(gca,'FontSize',TextSize)
% ylim([0,YMax]);
xlabel('\beta_2')
set(gcf,'Position',[50,50,1200,500]);
if SavePlots
FileName=[BasePlotFileName,'1'];
saveas(gcf,[FileName,'.jpg']);
saveas(gcf,[FileName,'.emf']);
end